package chaoyue.study.exception;

import lombok.Getter;

/**
 * 自定义异常
 * 继承RuntimeException表示当前异常是非受检异常，不需要显示的声明throw
 */
@Getter
public class MyException extends RuntimeException {
    private String code;

    public MyException() {
        super();
    }

    public MyException(String code, String message) {
        super(message);
        this.code = code;
    }

    public MyException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public MyException(Throwable cause) {
        super(cause);
    }

    public static void main(String[] args){
        doSome1();
        doSome2();
    }

    private static void doSome1(){
        throw new MyException("testCode1", "testMessage1");
    }

    /**
     * 也可以声明throws，编译器并不会强制要求调用者处理这异常
     */
    private static void doSome2() throws MyException{
        throw new MyException("testCode2", "testMessage2");
    }
}
